package xyz.mimai.media.netty.tcp.resolve;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @ClassName MessageUnitEncoder
 * @Description 消息编码器
 * @Author 方丈
 * @Date 2021/2/23 10:32
 * @Version 1.0.0
 **/
public class MessageUnitEncoder extends MessageToByteEncoder<MessageUnit> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, MessageUnit messageUnit, ByteBuf byteBuf) throws Exception {
        byteBuf.writeInt(messageUnit.length);
        byteBuf.writeBytes(messageUnit.getContent());
        System.out.println("编码器MessageUnitEncoder调用完成");
    }
}
